package com.tuozixuan.jmh.demo;

import java.util.concurrent.TimeUnit;

import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Warmup;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

public class Demo {

	@Benchmark
	@BenchmarkMode(Mode.AverageTime)
	@OutputTimeUnit(TimeUnit.NANOSECONDS)
	@Measurement(iterations = 2, time = 1, timeUnit = TimeUnit.SECONDS)
	@Warmup(iterations = 3, time = 1, timeUnit = TimeUnit.SECONDS)
	@Fork(1)
	public void testStringAdd() {
		String a = "";
		for (int i = 0; i < 100; i++) {
			a += "ab";
		}
	}

	public static void main(String[] args) throws RunnerException {
		Options opt = new OptionsBuilder().include(Demo.class.getSimpleName()).build();
		new Runner(opt).run();
	}
}
